package cn.stylefeng.guns.orderitem.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.orderitem.dto.OrderItemDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import cn.stylefeng.guns.orderitem.service.OrderItemService;
import cn.stylefeng.guns.orderitem.model.param.OrderItemParam;

import javax.annotation.Resource;

/**
 * order_item 控制器
 *
 * @author: aria
 * @date: 2021/02/20 20:24
 */
@RestController
public class OrderItemController {

    @Resource
    private OrderItemService orderItemService;

    /**
     * 分页查询order_item
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @GetMapping("/orderItem/page")
    @BusinessLog(title = "order_item_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(OrderItemParam orderItemParam) {
        OrderItemDTO orderItemDTO = new OrderItemDTO();
        BeanUtil.copyProperties(orderItemParam,orderItemDTO);
        return new SuccessResponseData(orderItemService.page(orderItemDTO));
    }

    /**
     * 获取全部order_item
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @GetMapping("/orderItem/list")
    @BusinessLog(title = "order_item_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(OrderItemParam orderItemParam) {
        OrderItemDTO orderItemDTO = new OrderItemDTO();
        BeanUtil.copyProperties(orderItemParam,orderItemDTO);
        return new SuccessResponseData(orderItemService.list(orderItemDTO));
    }

    /**
     * 查看详情order_item
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @GetMapping("/orderItem/detail")
    @BusinessLog(title = "order_item_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(OrderItemParam.detail.class) OrderItemParam orderItemParam) {
        OrderItemDTO orderItemDTO = new OrderItemDTO();
        BeanUtil.copyProperties(orderItemParam,orderItemDTO);
        return new SuccessResponseData(orderItemService.detail(orderItemDTO));
    }

    /**
     * 添加order_item
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @PostMapping("/orderItem/add")
    @BusinessLog(title = "order_item_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(OrderItemParam.add.class) OrderItemParam orderItemParam) {
        OrderItemDTO orderItemDTO = new OrderItemDTO();
        BeanUtil.copyProperties(orderItemParam,orderItemDTO);
        orderItemService.add(orderItemDTO);
        return new SuccessResponseData();
    }

    /**
     * 删除order_item
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @PostMapping("/orderItem/delete")
    @BusinessLog(title = "order_item_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(OrderItemParam.delete.class) OrderItemParam orderItemParam) {
        OrderItemDTO orderItemDTO = new OrderItemDTO();
        BeanUtil.copyProperties(orderItemParam,orderItemDTO);
        orderItemService.delete(orderItemDTO);
        return new SuccessResponseData();
    }

    /**
     * 编辑order_item
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @PostMapping("/orderItem/edit")
    @BusinessLog(title = "order_item_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(OrderItemParam.edit.class) OrderItemParam orderItemParam) {
        OrderItemDTO orderItemDTO = new OrderItemDTO();
        BeanUtil.copyProperties(orderItemParam,orderItemDTO);
        orderItemService.edit(orderItemDTO);
        return new SuccessResponseData();
    }


}
